# -*- coding: utf-8 -*-
"""
音频信息采集类，保存音频的重要参数
    1、Sonic类
        1-1、channels: 声道数
        1-2、sample_width: 采样字节宽度
        1-3、sample_frequency: 采样频率
        1-4、sample_length: 采样长度点数
        1-5、wave_bin_data: 采样音频的二进制数据
        1-6、update_wave_data(self, wave_bin_data, sample_length=0): 更新音频的【采样音频的二进制数据】、【采样长度点数】两个数据值
"""
import numpy


number_type = {1: numpy.int8, 2: numpy.int16, 3: numpy.int32}


class Sonic:
    """
    音频信息采集类
        :param channels: 声道数
        :param sample_width: 采样字节宽度
        :param sample_frequency: 采样频率
        :param sample_length: 采样长度点数
        :param wave_bin_data: 采样音频的二进制数据
    """
    def __init__(self, channels=1, sample_width=2, sample_frequency=16000, sample_length=0, wave_bin_data=None):
        self.channels = channels
        self.sample_width = sample_width
        self.sample_frequency = sample_frequency
        self.sample_length = sample_length
        self.wave_bin_data = wave_bin_data

    def update_wave_data(self, wave_bin_data, sample_length=0):
        if wave_bin_data and not sample_length:
            sample_length = len(wave_bin_data) / self.sample_width
        self.wave_bin_data = wave_bin_data
        self.sample_length = sample_length

